<?php
include('class/class_connect.php');
include('class/class_page.php');
include('class/class_news.php');
include('class/class_acts.php');
include('class/class_address.php');
include('class/class_workdays.php');
include('class/class_rating.php');
include('class/tabs/class_tabs.php');
include('class/abstract/class_mainObjectInfo.php');
include('class/city_rus.php');
include('class/class_checkGetData.php');


$aCheck=new checkGetData('m');
$aCheck->checkTableId($_GET['city'], $_GET['id']);
session_start();
$aConnect=new connect('m');
$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
if(strtolower($_SESSION['login'])!=strtolower($row['user']))header('location: registr.php');

if(!isset($_SESSION['login']))header('location: registr.php');

class aFirmPage extends page
{
	var $row=array();
	var $cityRus;
	function __construct()
	{
		$aConnect=new connect('m');
		$this->row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$this->cityRus=new city_rus_class();
		parent::__construct();
	}
	function title()
	{
		echo $this->row['name'].' '.$this->cityRus->city_rus_im($_GET['city']);
	}
	function maincontent()
	{
		echo ('
		<div class="photoFrame">
		</div>
		<div class="route">
			<div class="routeEl">
				<a href="pcabinet.php?city='.$_GET['city'].'">Личный кабинет</a>
			</div>
			<div class="routeEl">
				<a href="my_malls.php?city='.$_GET['city'].'">Мои центры</a>
			</div>
			<div class="routeEl">
				'.$this->row['name'].'
			</div>
		</div>
		<link rel="stylesheet" type="text/css" href="style/cabinet.css" />
		<link rel="stylesheet" type="text/css" href="style/malls.css" />
		');
		$aFirmInfo=new aFirmInfo($this->row);
    	$aTab=new aFirmTabs($this->row);
	}
}

class aFirmTabs extends tabs
{
	var $row;
	var $text;
	var $price;
	function __construct($row=array())
	{
		$aConnect=new connect('p');
		$r=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'"));
		$labels=array('Основная', 'О компании', 'Новости', 'События', 'Фирмы');
		$this->row=$row;
		parent::__construct($labels);
	}
	function content0()
	{
		$this->cab_panel($this->row['id']);
	}
	function content1()
	{
		//$aConnect=new connect('malls');
		//$this->row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$text=nl2br($this->row['stext']);
		echo ('
		<script type="text/javascript" src="scripts/showPhoto.js">
		</script>
		<link rel="stylesheet" type="text/css" href="style/aboutFirms.css" />

		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].''))
			{
				for($i=1; $i<=5; $i++)
				{
					if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<div class="aPhoto">
								<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
							</div>
						</td>
						');
					}
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		<div class="textTitle">
			'.$this->row['text_title'].'
		</div>
		<div class="firmText">
			'.$text.'
		</div>
		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].''))
			{
				for($i=6; $i<=10; $i++)
				{
					if(file_exists('pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<div class="aPhoto">
								<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="pictures/mallsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
						    </div>
						</td>
						');
					}
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		<div class="cab-panel">
			<div class="cab-panel-link">
				<a href="addmallsphoto.php?city='.$_GET['city'].'&id='.$_GET['id'].'" class="belink">Добавить фото</a>
			</div>
		</div>
		');


	}
	function content2()
	{
		$aNews=new news('malls', $_GET['city'], $_GET['id'], true);
		$newsConnect=new connect('mn');
		$newsesNum=mysql_num_rows(connect::select_all($_GET['city'], "WHERE malls_id='".$_GET['id']."'"));
		if($newsesNum==0)$newsesName="Новостей нет";
		else if($newsesNum<=3)$newsesName="Все новости";
		else $newsesName="Последние новости";
		echo ('<center><h4>'.$newsesName.'</h4></center>');
		$aNews->showNews('editmallsnews.php?city='.$_GET['city'].'&id='.$_GET['id'], 7, 200, "950px");
		echo ('
		<div class="cab-panel">
			<div class="cab-panel-link">
				<a href="addmallsnews.php?city='.$_GET['city'].'&id='.$id.'" class="belink">Добавить новость</a>
			</div>
		</div>
		');
	}
	function content3()
	{
		$act=new acts();
		$act->showActs('malls', 4, 200, $_GET['id'], true, "950px");
		echo ('
		<div class="cab-panel">
   			<div class="cab-panel-link">
				<a class="belink" href="addmallsacts.php?city='.$_GET['city'].'&id='.$_GET['id'].'">
					Добавить событие
				</a>
			</div>
		</div>
		');
	}
	function content4()
	{
echo ('
		<h4 class="textTitle">Наши фирмы</h4>
		');
		$mallsFirmsArray=explode('|', $this->row['firms']);
		for($i=0; $i<count($mallsFirmsArray); $i++)
		{
			$aMallsFirm=$mallsFirmsArray[$i];
			$aMallsFirmEl=explode('^', $aMallsFirm);
			$aMallsFirmId=$aMallsFirmEl[0];
			$aMallsFirmName=$aMallsFirmEl[1];
			$aMallsFirmSubdiv=$aMallsFirmEl[2];
			$aFirm[$aMallsFirmSubdiv][]=$aMallsFirmId.','.$aMallsFirmName;

		}
		//print_r($aFirm);
		arsort($aFirm);
		//print_r($aFirm);
		//$subdivSort=0;
		echo ('
		<input id="mallsId" name="mallsId" type="hidden" value="'.$_GET['id'].'">
		');
		$n=0;
		foreach($aFirm as $aFirm=>$subdiv)
		{
			if($n==4)break;
			$n++;
			echo ('
			<div class="mallsSubdiv" align="center">
				<a href="mallsFirmsCab.php?city='.$_GET['city'].'&id='.$_GET['id'].'&mallsSearch='.$aFirm.'">'.$aFirm.' ('.count($subdiv).')</a>
			</div>
			<div class="mallsFirmsList">
			');
			for($i=0; $i<4; $i++)
			{
				$aFirmsId=$subdiv[$i];
				$firmsIdNameArray=explode(',', $subdiv[$i]);
				$aFirmsId=$firmsIdNameArray[0];
				$aFirmsName=$firmsIdNameArray[1];
				echo ('

					<a href="mallsFirmsCab.php?city='.$_GET['city'].'&id='.$_GET['id'].'">
						<div class="mallsFirms">
						');
						if(file_exists('pictures/firmspics/'.$_GET['city'].'/'.$aFirmsId.'.jpg'))
							echo ('
							<img class="mallsPics" src="pictures/firmspics/'.$_GET['city'].'/'.$aFirmsId.'.jpg" title="'.$aFirmsName.'" />
							');
						echo ('
						</div>
					</a>

				');
			}
			echo ('
			</div>
			');

		}
        echo ('
        <center>
        	<a class="belink" href="mallsFirmsCab.php?city='.$_GET['city'].'&id='.$_GET['id'].'">Показать все фирмы</a>
        </center>
        <div class="cab-panel">
			<div class="cab-panel-link">
				<a class="belink" href="addmallsfirms.php?city='.$_GET['city'].'&id='.$_GET['id'].'">Добавить фирмы</a>
			</div>
		</div>
        ');

	}
	function cab_panel($id)
	{
		echo ('
		<div class="cab-panel">
			<div class="cab-panel-link">
				<a href="editmalls.php?city='.$_GET['city'].'&id='.$id.'" class="belink">Редактировать</a>
			</div>
			<div class="cab-panel-link">
				<a href="addmallsphoto.php?city='.$_GET['city'].'&id='.$id.'" class="belink">Добавить Фото</a>
			</div>
			<div class="cab-panel-link">
				<a href="addmallsnews.php?city='.$_GET['city'].'&id='.$id.'" class="belink">Добавить новость</a>
			</div>
			<div class="cab-panel-link">
				<a href="addmallsacts.php?city='.$_GET['city'].'&id='.$id.'" class="belink">Добавить событие</a>
			</div>
			<div class="cab-panel-link">
				<a class="belink" href="addmallsfirms.php?city='.$_GET['city'].'&id='.$_GET['id'].'">Добавить фирмы</a>
			</div>
		</div>
		');
	}
}

class aFirmInfo extends mainObjectInfo
{
	var $row;
	function __construct($row=array())
	{
		$this->row=$row;
		parent::__construct();
	}
	function showPic()
	{
		echo ('
		<img src="pictures/mallspics/'.$_GET['city'].'/'.$this->row['id'].'.jpg" title="'.$this->name.'">
		');
		$aFirmRating=new rating('malls');
		$aFirmRating->echo_rating(0, $this->row['rating'], $this->row['votes']);
	}
	function showAddress()
	{
		$address=new address();
		$explAddress=explode(',', $this->row['address']);
		$thisaddress=$explAddress[0].'^'.$explAddress[1].'^'.$this->row['phone'].'^^'.$this->row['workdays'];
		$address->showAddress($thisaddress, $this->row['link']);
	}
	function showshort()
	{
		echo $this->row['short'];
	}
	function showName()
	{
		echo $this->row['name'];
	}
}
$aPage=new aFirmPage();

?>